﻿using Microsoft.AspNetCore.Mvc;
using ZhCun.DbCore.Entitys;
using ZhCun.Utils;
using ZhCun.WebUtils.DB;
using ZhCun.WebUtils.VModel;

namespace ZhCun.WebUtils
{
    public class BaseApiCrudController<TAL, TListArg, TSaveModel> : BaseApiCrudController<TAL, TListArg, TSaveModel, TSaveModel>
        where TListArg : ArgGetList, new()
        where TSaveModel : EntityBase, new()
        where TAL : BLLCrudBase<TListArg, TSaveModel>, new()
    { }

    public class BaseApiCrudController<TAL, TListArg, TSaveModel, TListModel> : BaseApiController<TAL>
        where TListArg : ArgGetList, new()
        where TSaveModel : EntityBase, new()
        where TListModel : EntityBase, new()
        where TAL : BLLCrudBase<TListArg, TSaveModel, TListModel>, new()
    {
        /// <summary>
        /// 获取列表
        /// </summary>
        [HttpPost]
        public virtual ApiResultList<TListModel> GetList(TListArg arg)
        {
            return BLLObj.GetList(arg);
        }
        /// <summary>
        /// 新增
        /// </summary>
        [HttpPost]
        public virtual ApiResult Add(TSaveModel arg)
        {
            return BLLObj.Add(arg);
        }
        /// <summary>
        /// 更新
        /// </summary>
        [HttpPost]
        public virtual ApiResult Update(TSaveModel arg)
        {
            return BLLObj.Update(arg);
        }
        /// <summary>
        /// 删除
        /// </summary>
        [HttpPost]
        public virtual ApiResult Del(ArgId arg)
        {
            return BLLObj.Del(arg.Id);
        }
    }
}